{extend name="../../public/admin"}
{block name="title"}设置管理员权限{/block}
{block name="css"}
<link rel="stylesheet" href="__PUBLIC__/admin/css/user.admin_set.css">
{/block}
{block name="body"}
<ul class="list-unstyled list-group" id="data">
    <template v-for="(key,index) in list">
        <li class="list-group-item navList" @click="nav(index)">
            <span class="">{{key[0].parentname}}</span>
            <span class="fa-pull-right"><i class="fa fa-angle-down"></i></span>
            <ul class="list-unstyled nei_rong" @click.stop="">
                <template v-for="(key2,index2) in list[index]">
                    <li>
                        <div class="checkbox">
                            <label>
                                <input type="checkbox" @click.stop="one_cha(key2,$($event.target))" v-model="key2.state"> {{key2.navname}}
                            </label>
                        </div>
                    </li>
                </template>
            </ul>

        </li>
    </template>
</ul>

{/block}
{block name="js"}
<script>
    var app = new Vue({
        el:'#data',
        data:{
            list:[],
            show:0,
            che:{$url}
        }
    });
    /*点击展开内容*/
    app.nav = (i)=>{
        $('.navList').eq(i).find('.nei_rong').slideToggle();
    }

    //单选内容
    app.one_cha = (key,$this)=>{
        postData(key.navid,$this.is(':checked'));
    }
    get_data();
    //获取数据
    function get_data() {
        $.get(DINDEX+'/nav',function (da) {
            app.list = da;
            //添加选中状态
            $.each(app.list,function (i,n) {
                $.each(app.list[i],function (i2,n2) {
                    $.each(app.che,function (cheI,cheN) {
                        if(cheN.menu_id == n2.navid){
                            app.list[i][i2].state = true;
                            return false;
                        }
                        else {
                            app.list[i][i2].state = false;
                        }


                    })
                })
            })
        });
    }

    //发送数据 id1,id2,id3... $type=false:删除 true:添加
    function postData($id,$type=false) {
        var user = {$id};
        $type == false?$type = 0:$type=1;
       $.post(DUSER+'/admin_set',{id:$id,type:$type,user:user})
    }


</script>
{/block}